﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CSDemo.Common;
using Hik.Communication.Scs.Communication.EndPoints.Tcp;
using Hik.Communication.ScsServices.Client;

namespace CSDemo.SCS.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();

            for (int i = 0; i < 1000; i++)
            {
                //10048 TCP port.
                var client = ScsServiceClientBuilder.CreateClient<IProductService>(
                    new ScsTcpEndPoint("127.0.0.1", 10048));
                client.Connect();
                var product1 = new Product()
                {
                    Name = "索尼 MP3 "+i,
                    Price = 100,
                    CreateTime = DateTime.Now,
                    OnSale = true
                };
                var product2 =
                  new Product
                  {
                      Name = "Apple Ipad mini 4 "+i,
                      Price = 3000,
                      CreateTime = DateTime.Now,
                      OnSale = true
                  };
                client.ServiceProxy.AddProduct(product1);
                client.ServiceProxy.AddProduct(product2);
                var person = client.ServiceProxy.GetProduct("MP3");
                if (person != null)
                {
                    Console.WriteLine("商品找到");
                    Console.WriteLine(person);
                }
                else
                {
                    Console.WriteLine("找不到商品");
                }
                client.Disconnect();
            }
            watch.Stop();
            Console.WriteLine("1000次连接共耗时：{0}ms",watch.ElapsedMilliseconds);
            Console.ReadLine();

        }
    }
}
